<?php
class App_Source_Values{

	public static function TimeZonesSource()
	{
		return Mozg::Lib('date')->GetTimeZoneOptions();
	}

	public static function LanguagesSource()
	{
		return array('auto' => Mozg_Lang::_('AUTO'), 'ru' => 'Русский', 'en' => 'English');
	}

	public static function PagesSource()
	{
		return array(1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 10 => '10', 15 => '15', 20 => '20', 25 => '25', 30 => '30', 40 => '40', 50 => '50', 60 => '60', 70=> '70', 80=> '80', 90=> '90', 100 => '100');
	}

	public static function YesNoSource()
	{
		return array(0 => Mozg_Lang::_('NO'), 1 => Mozg_Lang::_('YES'));
	}

	public static function LangsSource()
	{
		$selects = array();
		foreach (Mozg_Lang::$langs as $lang)
		{
			$selects[$lang] = Mozg_Lang::_($lang);
		}

		return $selects;
	}

	public static function PageTypesSource()
	{
		$pageTypes = Mozg_Cfg::Get('global/structure')->GetPageTypes();
		$selects = array();
		foreach ($pageTypes as $typeId => $typeData)
		{
			$selects[$typeId] = Mozg_Lang::_($typeData['name']);
		}

		return $selects;
	}

	static protected $_newsCategoryPageType = 2;

	public static function ArticleCategoriesSource()
	{
		$structure = Mozg_Mapper::Get('Structure');
		$newsCategories = $structure->GetList(array('pageType' => self::$_newsCategoryPageType));

		$categories = array();
		foreach ($newsCategories as $cat)
		{
			$html = '<small>';

			$parentCats = $structure->GetList(array('pathId' => $cat->GetId()));
			foreach ($parentCats as $pCat)
			{
				$html .= $pCat->GetName(). ' &gt; ';
			}

			$html .= '</small>' .$cat->GetName();

			$categories[$cat->GetId()] = $html;
		}

		return $categories;
	}

	public static function ParentGroupsSource()
	{
		$groups = array();

		$grMapper = Mozg_Mapper::Get('Groups');

		$gr = Mozg::User()->GetGrantedGroups();
		array_unshift($gr, Mozg::User()->GetGroup()->GetId());
		$gr = array_unique(array_merge($gr, Mozg::User()->GetAvailableGroups()));
		foreach ($gr as $grId)
		{
			$group = $grMapper->GetOne(array('id' => $grId));
			if (!$group) continue;

			$groups[$grId] = $group->GetTitle();
		}

		return $groups;
	}

	public static function AvailableGroupsSource()
	{
		$groupsMapper = Mozg_Mapper::Get('Groups');
        $myGroupsIds = Mozg::User()->GetAvailableGroups();
        $myGroups = array();
        while (list(, $id) = each($myGroupsIds))
        {
     		$group = $groupsMapper->GetOne(array('id' => $id));
			if (!$group) continue;

     		$myGroups[$id] = $group->GetTitle();
        }

        return $myGroups;
	}

}